package com.linxianqin.mapstruct.simpleDemo.convert;

import com.linxianqin.mapstruct.simpleDemo.dto.UserDTO;
import com.linxianqin.mapstruct.simpleDemo.entity.User;
import com.linxianqin.mapstruct.simpleDemo.vo.UserVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * 功能描述：
 *
 * @author lxq
 * @version 1.00
 * @Date 2020/12/14
 */
@Mapper
public interface UserConvert {
    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    /**
     * user转userDTO
     * @param user
     * @return
     */
    UserDTO entity2dto(User user);

    /**
     * UserDTO转UserVO实现
     * */
    @Mappings(value = {
            @Mapping(source = "id",target = "userId"),
            @Mapping(source = "name", target = "userName"),
            @Mapping(source = "sex", target = "userSex"),
            @Mapping(source = "className",target = "userClassName" ),
            @Mapping(source = "school",target = "userSchool"),
            //使用expression指定处理target
            @Mapping(target = "date",expression =  "java(new java.util.Date())"),
            @Mapping(target = "phone",ignore = true)//忽略字段
    })
    UserVO dto2Vo(UserDTO userDTO);
}
